package cn.com.bdqn.dao;

import cn.com.bdqn.entity.CstService;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface CstServiceDao {

    @Insert("insert into cst_service(svr_id,svr_type,svr_title,svr_cust_no,svr_status,svr_request,svr_create_id,svr_create_date) values\n" +
            "(default,#{svrType},#{svrTitle},#{svrCustNo},0,#{svrRequest},#{svrCreateId},now())")
    public int addCstService(CstService cstService);

    @Update("update cst_service set svr_due_id = #{svrDueId},svr_due_date = now(),svr_status = 1 where svr_id = #{svrId}")
    public int assignment(CstService cstService);

    public List<Map> queryByLike(CstService cstService);

    @Delete("delete from cst_service where svr_id = #{value}")
    public int delCstService(Long svrId);

    @Update("update cst_service set svr_deal = #{svrDeal},svr_deal_id = #{svrDealId},svr_deal_date = #{svrDealDate},svr_status = 2 where svr_id = #{svrId}")
    public int dispose(CstService cstService);

    @Update("update cst_service set svr_result = #{svrResult},svr_satisfy = #{svrSatisfy},svr_status = 3 where svr_id = #{svrId}")
    public int feedback(CstService cstService);

    @Update("update cst_service set svr_deal = null,svr_deal_id = null,svr_deal_date = null,svr_result = null,svr_satisfy = null,svr_status = 1 where svr_id = #{value}")
    public int anew(CstService cstService);

    @Select("select *,(select usr_name from sys_user where usr_id = svr_create_id) as svr_create_name,\n" +
            "(select usr_name from sys_user where usr_id = svr_due_id) as svr_due_name,\n" +
            "(select usr_name from sys_user where usr_id = svr_deal_id) as svr_deal_name,\n" +
            "(select cust_name from cst_customer where cust_no = svr_cust_no) as svr_cust_name\n" +
            "from cst_service where svr_id = #{value}")
    public Map queryBySvrId(Long svrId);
}
